package com.wc.AlgoOJ_train.train3_算法大礼包.c1_广度优先搜索.AG0201_抓住那头熊;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/24 21:35
 * @description http://43.138.190.70:8888/p/AG0201
 */
public class Main {
    static int N = (int) 1e5 + 10;
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int[] f = new int[N];
    static int n, k;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        System.out.println(bfs(n));
    }

    static int bfs(int x) {
        Queue<Integer> q = new LinkedList<>();
        q.add(x);
        while (true) {
            x = q.poll();
            if (x == k) {
                return f[x];
            }
            // 表示不是第一次到达
            if (x + 1 < N && f[x + 1] == 0) {
                f[x + 1] = f[x] + 1;
                q.add(x + 1);
            }
            if (x - 1 >= 0 && f[x - 1] == 0) {
                f[x - 1] = f[x] + 1;
                q.add(x - 1);
            }
            if (2 * x < N && f[2 * x] == 0) {
                f[x * 2] = f[x] + 1;
                q.add(2 * x);
            }
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

